package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjWorkLevelService;
import com.zb.utils.TokenUtil;
import com.zb.vo.WorkLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 工单等级表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-12
 */
@Api(tags = "工单级别类接口")
@RestController
@RequestMapping("/work/level")
public class ZjWorkLevelController {
    @Resource
    private ZjWorkLevelService workLevelService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "工单管理-工单设置-工单策略-工单级别 - 新增或修改工单级别")
    @ApiOperation("新增或修改工单级别")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkLevelVo workLevelVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        workLevelService.save(custAccId, workLevelVo);
        return Result.success(null == workLevelVo.getId()? "新增级别成功" : "修改级别成功");
    }

    @ApiOperation("获取工单级别列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody SelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单级别列表成功").data(workLevelService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据级别ID获取工单级别详情")
    @GetMapping("/getDetail/{id}")
    public Result getDetail(@PathVariable @ApiParam(value = "级别ID", required = true) Long id) {
        return Result.success("获取工单级别详情成功").data("row", workLevelService.getDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "工单管理-工单设置-工单策略-工单级别 - 根据级别ID批量启用或禁用工单级别")
    @ApiOperation("根据级别ID批量启用或禁用工单级别")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "级别状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "级别ID集合", required = true) List<Long> idList) {
        workLevelService.updateDisabledBatchById(idList, status);
        return Result.success(status? "禁用级别成功" : "启用级别成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.DELETE, remark = "工单管理-工单设置-工单策略-工单级别 - 根据级别ID批量删除工单级别")
    @ApiOperation("根据级别ID批量删除工单级别")
    @DeleteMapping("/delete")
    public Result delete(@RequestBody @ApiParam(value = "级别ID集合", required = true) List<Long> idList) {
        workLevelService.deleteBatchById(idList);
        return Result.success("删除级别成功");
    }

}
